package com.config;


import lombok.Data;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@PropertySource("classpath:weixin.properties")
@ConfigurationProperties(prefix = "weixin.gzh")
@Data
public class WeixinPropertiesConfig {
    private String appid;
    private String appsecret;

    @Bean
    public WxMpConfigStorage wxMpConfigStorage(){
        WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage() ;
        config.setAppId(appid); // 设置微信公众号的appid
        config.setSecret(appsecret); // 设置微信公众号的app corpSecret
        //config.setToken(gzhConfig.getToken()); // 设置微信公众号的token
        //config.setAesKey(gzhConfig.getEncodingAESKey()); // 设置微信公众号的EncodingAESKey
        return config ;
    }


    @Bean
    public WxMpService wxMpService()
    {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;

    }


}
